package com.osmino.contacts.dialer;

import android.app.Activity;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.osmino.contacts.R;
import com.osmino.contacts.dialer.Dialer.DialerClient;
import com.osmino.core.ICustomisableView;
import com.osmino.core.style.Style;

public class DialerView extends RelativeLayout implements ICustomisableView, DialerClient {

	private boolean DBG = true;
	private IDialerController mController;
	private Dialer mDialer;
	private ListView mListView;
	private final int LAYOUT_LIST = R.layout.contacts_view;
	private TextView mTitleBarText;

	public DialerView(Activity activity, IDialerController controller, 
			Style style) {
		super(activity);
		activity.getLayoutInflater().inflate(LAYOUT_LIST, this);
		findViewById(R.id.contacts_search_text).setVisibility(GONE);
		this.mController = controller;
		mDialer = new Dialer(activity, this, style);
		mListView = (ListView) findViewById(android.R.id.list);
		mListView.setOnItemClickListener(mController);
		RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(-1, -1);
		addView(mDialer, lp);
		mTitleBarText = (TextView) findViewById(R.id.title_bar_text);
		findViewById(R.id.title_bar_edit_icon).setVisibility(GONE);
		mTitleBarText.setText("Keypad");
	}

	public void switchBetweenDialerAndList() {
		int curVis = mDialer.getVisibility();
		mDialer.setVisibility(curVis == INVISIBLE ? VISIBLE : INVISIBLE);
	}

	@Override
	public void setStyle(Style style) {
	}
	
	public ListView getListView() {
		return mListView;
	}

	@Override
	public void onCall(String phoneNumber) {
		mController.onCallTap(phoneNumber);
	}

	@Override
	public void onTextChanged(String text) {
		mController.onTextChanged(text);
	}
	
	@Override
	public void onDialerButtonClick() {
		mController.onDialerButtonClick();
	}
	
	public String getText() {
		return mDialer.getText();
	}
}